defmodule ProgContest.Quizzes.Quiz do
  use Ecto.Schema
  import Ecto.Changeset

  alias ProgContest.Contests.Contest

  schema "quizzes" do
    field :author, :string
    field :question, :string
    field :title, :string

    belongs_to :contest, Contest

    timestamps(type: :utc_datetime)
  end

  @doc false
  def changeset(quiz, attrs) do
    quiz
    |> cast(attrs, [:title, :question, :author, :contest_id])
    |> validate_required([:title, :question, :author, :contest_id])
    |> assoc_constraint(:contest)
  end
end
